package com.document;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

import com.DBHelper.MySQLIteOpenHelper;
import com.document.changeSkin.SkinSettingManager;

public class MyActivity extends Activity {
	private SkinSettingManager mSettingManager;
	 private RadioButton radioButton1;
	 private RadioButton radioButton2;
	 private RadioButton radioButton3;
	 private RadioButton radioButton4;
	 private RadioButton radioButton5;
	 private Button suretochange;

	 @Override
	 public void onCreate(Bundle savedInstanceState) {
	  super.onCreate(savedInstanceState);
	  // 初始化皮肤
	  mSettingManager = new SkinSettingManager(this);
	  mSettingManager.initSkins();
	  setContentView(R.layout.myactivity);
	 

	  //通过单选按钮设置皮肤
	  radioButton1 = (RadioButton) findViewById(R.id.radioButton1);
	  radioButton2 = (RadioButton) findViewById(R.id.radioButton2);
	  radioButton3 = (RadioButton) findViewById(R.id.radioButton3);
	  radioButton4 = (RadioButton) findViewById(R.id.radioButton4);
	  radioButton5 = (RadioButton) findViewById(R.id.radioButton5);
	  suretochange=(Button)findViewById(R.id.suretochange);
	  RadioGroup radioGroup = (RadioGroup) findViewById(R.id.skin_options);
	  radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

	   @Override
	   public void onCheckedChanged(RadioGroup group, int checkedId) {

	    switch (checkedId) {
	    case R.id.radioButton1:
	     mSettingManager.changeSkin(1);
	     break;

	    case R.id.radioButton2:
	     mSettingManager.changeSkin(2);
	     break;
	    case R.id.radioButton3:
	     mSettingManager.changeSkin(3);
	     break;
	    case R.id.radioButton4:
	     mSettingManager.changeSkin(4);
	     break;
	    case R.id.radioButton5:
	     mSettingManager.changeSkin(5);
	     break;
	    default:
	     break;
	    }
	   }
	  });
	  suretochange.setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			Intent i=new Intent();
			i.setClass(getApplicationContext(), MainActivity.class);
			startActivity(i);
			finish();
			
		}
	});
	 }
	   //监听返回按钮事件，离开界面清除数据库数据
	   public boolean onKeyDown(int keyCode, KeyEvent event) {
		  
		           if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
		  
		        	   MySQLIteOpenHelper helper=new MySQLIteOpenHelper(getApplicationContext());
						 helper.delete("delete from FileName");
						 helper.close();
						 Intent i=new Intent();
						 i.setClass(getApplicationContext(), MainActivity.class);
						 startActivity(i);
						 finish();
		  
		               return false;
		
		           }
		
		           return false;
		 
		       }
	



	}
